home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / UUCICO / ULIB14.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  19KB  |  488 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       u l i b 1 4 . c                                              */
  3. /*                                                                    */
  4. /*       Serial port communications driver for ARTICOMM INT14         */
  5. /*       driver                                                       */
  6. /*--------------------------------------------------------------------*/
  7.  
  8. /*--------------------------------------------------------------------*/
  9. /*    Copyright (c) Richard H. Lamb 1985-1987                         */
  10. /*                                                                    */
  11. /*    Changes Copyright 1992 by Mark W. Schumann                      */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. /*--------------------------------------------------------------------*/
  15. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  16. /*    Wonderworks.                                                    */
  17. /*                                                                    */
  18. /*    All rights reserved except those explicitly granted by the      */
  19. /*    UUPC/extended license agreement.                                */
  20. /*--------------------------------------------------------------------*/
  21.  
  22. /*--------------------------------------------------------------------*/
  23. /*       This suite needs some tuning, but the Wonderworks lacks      */
  24. /*       the time and more importantly the software to do so.         */
  25. /*       Specific problems:                                           */
  26. /*                                                                    */
  27. /*          The INT14 interface is not checked to be ARTICOMM, and    */
  28. /*          thus the extensions to the generic INT14 functions may    */
  29. /*          fail with no warning to the user.                         */
  30. /*                                                                    */
  31. /*          Non-ARTICOMM programs are not supported.                  */
  32. /*                                                                    */
  33. /*          No error is returned if a write times out                 */
  34. /*                                                                    */
  35. /*          Input data is discarded if a read times out, which        */
  36. /*          will confuse the 'g' packet input processor.              */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. /*--------------------------------------------------------------------*/
  40. /*                          RCS Information                           */
  41. /*--------------------------------------------------------------------*/
  42.  
  43. /*
  44.  *    $Id: ulib14.c 1.3 1993/10/03 22:09:09 ahd Exp $
  45.  *
  46.  *    $Log: ulib14.c $
  47.  * Revision 1.3  1993/10/03  22:09:09  ahd
  48.  * Use unsigned long to display speed
  49.  *
  50.  * Revision 1.2  1993/05/30  15:25:50  ahd
  51.  * Multiple driver support
  52.  *
  53.  *
  54.  *   30 Nov 92 - Adapt for use with INT14 drivers.
  55.  *               Currently this is guaranteed to work only with
  56.  *               Artisoft's ARTICOMM driver, but porting to others
  57.  *               should be minor.  Mods by Mark W. Schumann
  58.  *               <mark@whizbang.wariat.org>
  59.  */
  60.  
  61. /*--------------------------------------------------------------------*/
  62. /*                        System include files                        */
  63. /*--------------------------------------------------------------------*/
  64.  
  65. #include <fcntl.h>
  66. #include <io.h>
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70. #include <time.h>
  71.  
  72. #include <dos.h>    /* Declares union REGS and int86(). */
  73.  
  74. /*--------------------------------------------------------------------*/
  75. /*                    UUPC/extended include files                     */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. #include "lib.h"
  79. #include "hlib.h"
  80. #include "ulib.h"
  81. #include "comm.h"          // Modem status bits
  82. #include "ssleep.h"
  83. #include "catcher.h"
  84.  
  85. #include "fossil.h"        // Various INT14 definitions
  86. #include "commlib.h"       // Trace functions, etc.
  87.  
  88. /*--------------------------------------------------------------------*/
  89. /*                        Internal prototypes                         */
  90. /*--------------------------------------------------------------------*/
  91.  
  92. static void modemControl( char mask, boolean on);
  93. static void ShowModem( void );
  94. static unsigned char bps_table(int);
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*                          Global variables                          */
  98. /*--------------------------------------------------------------------*/
  99.  
  100. static BPS currentBPS;
  101. static char currentDirect;
  102. static boolean carrierDetect;
  103.  
  104. currentfile();
  105. static boolean hangupNeeded = TRUE;
  106.  
  107.  
  108. /*--------------------------------------------------------------------*/
  109. /*    b p s _ t a b l e                                               */
  110. /*                                                                    */
  111. /*    Look up the INT14 baud rate value corresponding to (bps).       */
  112. /*--------------------------------------------------------------------*/
  113.  
  114. static unsigned char bps_table (int bps)
  115. {
  116.  
  117.    static int tab[] = {110, 150, 300, 600, 1200, 2400, 4800, 9600, -1};
  118.    unsigned char i;
  119.  
  120.    for (i = 0; tab[i] > 0; i++)
  121.    {
  122.       if (tab[i] == bps)
  123.          return i;
  124.    }
  125.  
  126.    return 255;
  127.  
  128. } /* bps_table */
  129.  
  130. /*--------------------------------------------------------------------*/
  131. /*    i o p e n l i n e                                               */
  132. /*                                                                    */
  133. /*    Open the serial port for I/O                                    */
  134. /*--------------------------------------------------------------------*/
  135.  
  136. int iopenline(char *name, BPS bps, const boolean direct)
  137. {
  138.  
  139.    if (portActive)              /* Was the port already active?      */
  140.       closeline();               /* Yes --> Shutdown it before open  */
  141.  
  142.    printmsg(15, "openline: %s, %lu", name, bps);
  143.  
  144.    currentDirect = (char) (direct ? 'D' : 'M');
  145.  
  146.    if (sscanf(name, "COM%d", &portNum) != 1)
  147.    {
  148.       printmsg(0,"Communications port must be format COMx, was %s",
  149.                 name);
  150.       panic();
  151.    }
  152.  
  153.    norecovery = FALSE;     // Flag we need a graceful shutdown after
  154.                            // Cntl-BREAK
  155.  
  156. /*--------------------------------------------------------------------*/
  157. /*       With the INT14 setup, we don't worry about the lock file     */
  158. /*       since our modem sharing software is supposed to deal with    */
  159. /*       resource contention.                                         */
  160. /*--------------------------------------------------------------------*/
  161.  
  162.    portNum--;              /* Change ordinal number to offset       */
  163.    SIOSpeed( bps );        /* Open the port and set the speed       */
  164.    flowcontrol( FALSE );   /* Enable hardware flow control          */
  165.  
  166.    ssleep(2);              /* Wait two seconds as required by V.24  */
  167.    carrierDetect = FALSE;  /* No modem connected yet                */
  168.  
  169.    traceStart( name );
  170.  
  171.    portActive = TRUE;     /* record status for error handler */
  172.  
  173.    return 0;               // Return success to caller
  174.  
  175. } /* iopenline */
  176.  
  177.  
  178. /*--------------------------------------------------------------------*/
  179. /*    i s r e a d                                                     */
  180. /*                                                                    */
  181. /*    Read from the serial port                                       */
  182. /*                                                                    */
  183. /*    Non-blocking read essential to "g" protocol.  See               */
  184. /*    "dcpgpkt.c" for description.  This all changes in a             */
  185. /*    multi-tasking system.  Requests for I/O should get queued       */
  186. /*    and an event flag given.  Then the requesting process (e.g.     */
  187. /*    gmachine()) waits for the event flag to fire processing         */
  188. /*    either a read o